package cn.bqjr.eily.samples.common.shiro;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListenerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Shiro会话监听器
 */
@Component
public class ShiroSessionListener extends SessionListenerAdapter {

    private static final Logger logger = LoggerFactory.getLogger(ShiroSessionListener.class);

    @Autowired
    private AuthLogAsync authLogAsync;

    @Override
    public void onStop(Session session) {
        logger.info("session：{} 已退出", session.getId());
        authLogAsync.updateLogoutLog(session);
    }

    @Override
    public void onExpiration(Session session) {
        logger.info("session：{} 已过期", session.getId());
        authLogAsync.updateLogoutLog(session);
    }
}
